<!DOCTYPE html>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page trimDirectiveWhitespaces="true"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	response.setHeader("pragma", "no-cache");
	response.setHeader("Cache-Control", "no-cache");

	// 動画情報取得
	request.setAttribute("target",
			jp.co.jmas.jmasvideo.Util.getVideo(request.getParameter("id")));

	// 動画一覧取得
	request.setAttribute("videoList",
			jp.co.jmas.jmasvideo.Util.getVideoList());

	// ユーザ情報取得
	request.setAttribute("user",
			jp.co.jmas.jmasvideo.Util.getUserData(request.getUserPrincipal().getName()));

	// UserServiceオブジェクト
	com.google.appengine.api.users.UserService service = com.google.appengine.api.users.UserServiceFactory
			.getUserService();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${target.title}</title>
</head>
<body>
	<%
		if (request.getUserPrincipal() == null) {
			// Loginしてない
			out.println("<a href=\"" + service.createLoginURL(request.getRequestURI()) + "\">login</a>");
		} else {
	%>
	<table style="text-align: left; width: 720px;" border="1"
		cellpadding="2" cellspacing="2" align="center">
		<tbody>
			<tr>
				<td style="vertical-align: top; width: 400px;">
					<h1>${target.title}</h1> <video controls width="480" height="360"
						poster="https://storage.cloud.google.com/jmas_camera/${target.key}.jpg">
						<source
							src="https://storage.cloud.google.com/jmas_camera/${target.key}.mp4"
							type="video/mp4">



					</video>
					<h2>${target.desc}</h2>
					<p>
						<small> 再生時間：${target.duration}<br>
							ファイルサイズ：${target.size}
						</small>
					</p>
					<p align="right">
						撮影日時：${target.date}<br> 最終更新日時：${target.lastUpdated}<br>
						削除予定日時：${target.expired}<br>
					</p>
				</td>

				<td style="vertical-align: top;">
					<p align="right">
						ユーザ情報<br> ID:${user.id}<br> ユーザ名：${user.name}<br>
						メールアドレス：${user.mail}<br>
						<%
							out.println("<a href=\"" + service.createLogoutURL(request.getRequestURI()) + "\">logout</a>");
						%>
					</p> <c:choose>
						<c:when test="${empty videoList}">
							<p>no video</p>
						</c:when>
						<c:otherwise>
							<table border="0">
								<c:forEach items="${videoList}" var="video">
									<tr>
										<td><image width="160" height="120"
												src="https://storage.cloud.google.com/jmas_camera/${video.key}.jpg">
											<td valign="top">
												<p>
													<c:out value='${video.title}' />
												</p>
												<p>
													<c:out value='${video.desc}' />
												</p>
											</td>
									</tr>
								</c:forEach>
							</table>
						</c:otherwise>
					</c:choose>
				</td>
			</tr>
		</tbody>
	</table>
	<%
		}
	%>
</body>
</html>
